home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
dialogs
/
restoreBkm.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
4KB
|
166 lines
/*
* restoreBkm.js
*
* @author alexandre poirot <poirot.alex@gmail.com>
* @copyright 2005-2008 Yoono
*/
const CI = Components.interfaces;
const CL = Components.classes;
const PREFS = CL['@mozilla.org/preferences-service;1'].getService(CI.nsIPrefBranch);
const PROMPT = CL["@mozilla.org/embedcomp/prompt-service;1"].getService(CI.nsIPromptService);
Components.utils.import("resource://yoono/yoonoBkmSync.js");
var gBkmService = YOONO_BKM;
var gBundle = null;
function onSelectBackup(elt) {
try {
var btn=document.getElementById('acceptbtn');
if (elt) {
var iframe=document.getElementById('backup-preview');
iframe.setAttribute("src","file://"+elt.backup.file.path);
btn.removeAttribute("disabled");
} else {
btn.setAttribute("disabled","true");
}
} catch(e) {
alert(e);
}
}
function onChangeMaxHistory(value) {
gBkmService.setMaxBackups(value);
reloadBackups();
}
function onAcceptDialog()
{
var list=document.getElementById("backups-list");
var selected=list.selectedItem;
// Ask confirmation for replacing BookMarkFile
if(selected && confirm(gBundle.getString("replacebookmarks.confirm")))
{
gBkmService.restore(selected.backup.name);
}
}
function onCancelDialog()
{
// Nothing to do
}
// Load backup list
function reloadBackups() {
var list=document.getElementById("backups-list");
while(list.firstChild)
list.removeChild(list.firstChild);
var backups = gBkmService.getBackupList();
for(var i=0;i<backups.length;i++) {
var b=backups[i];
var item=document.createElement("listitem");
item.setAttribute("label", b.date.toLocaleString());
item.backup=b;
list.appendChild(item);
}
var iframe=document.getElementById('backup-preview');
iframe.setAttribute("src","about:blank");
}
function onInitDialog()
{
try {
gBundle = document.getElementById("bundle");
reloadBackups();
// Set current history file number
var historyList=document.getElementById("maxhistorymenu");
historyList.selectedIndex = (gBkmService.getMaxBackups()/5)-1;
// Init iframe and watch for document loading
var iframe=document.getElementById('backup-preview');
iframe.addEventListener("DOMContentLoaded",function (event) {
try {
var doc = event.originalTarget;
// Add a css stylesheet and a javascript to make a dynamic tree
var css=doc.createElement("link");
css.setAttribute("rel","stylesheet");
css.setAttribute("href","chrome://yoono/skin/mktree.css");
css.setAttribute("type","text/css");
doc.documentElement.appendChild(css);
var js=doc.createElement("script");
js.setAttribute("src","chrome://yoono/content/dialogs/mktree.js");
js.setAttribute("type","text/javascript");
doc.documentElement.appendChild(js);
// Transform the original html which is very dirty to a clean <ul><li> list
function transformHTML(DL) {
try {
var list=doc.createElement("UL");
for(var i=0 ; i<DL.childNodes.length ; i++) {
var child=DL.childNodes[i];
if (child.tagName=="H3") { // we hit a folder
var item=doc.createElement("LI");
item.textContent=child.textContent;
var sub=DL.childNodes[i+2];
if (sub.tagName=="DD")
item.appendChild(transformHTML(sub.childNodes[1]));
else if (sub.tagName=="DL")
item.appendChild(transformHTML(sub));
else
alert("bad sub : "+sub.tagName);
list.appendChild(item);
i+=1; // ignore folder's childs ...
} else if (child.tagName=="DT" && child.firstChild && child.firstChild.tagName=="A") { // we hit a bookmark
var item=doc.createElement("LI");
item.textContent=child.firstChild.textContent;
list.appendChild(item);
}
}
return list;
} catch(e) {
alert("transform : "+e);
}
}
var DL=doc.body.childNodes[2];
if (DL) {
var list=transformHTML(DL);
list.setAttribute("class","mktree");
while(doc.body.firstChild)
doc.body.removeChild(doc.body.firstChild);
doc.body.appendChild(list, DL);
}
} catch(e) {
alert("load : "+e);
}
}, true);
} catch(e) {
alert(e);
}
}